/*
 * Copyright 2014 Walter Lütgenau.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package offset.nodes.client.dialog.navigation.model;

import netscape.javascript.JSObject;

/**
 *
 * @author Walter Lütgenau
 */
public class JSWindow extends JSNode {
    public static final String M_SCREEN_X = "screenX";
    public static final String M_SCREEN_Y = "screenY";
    public static final String M_INNER_WIDTH = "innerWidth";
    public static final String M_INNER_HEIGHT = "innerHeight";
    public static final String M_OUTER_WIDTH = "outerWidth";
    public static final String M_OUTER_HEIGHT = "outerHeight";
    public static final String M_LENGTH = "length";
    
    public static final String F_RUN_DIALOG = "runDialog";    
    public static final String F_RUN_ELEMENT_DIALOG = "runElementDialog";    
    public static final String F_RUN_JSF_ACTION = "runJSFAction";    
    
    public JSWindow(JSObject object) {
        super(object);
    }
    
    public JSWindow(JSNode node) {
        this(node.getObject());
    }
    
    public int getScreenX() {
        return JSUtil.getInt(getObject(), M_SCREEN_X);
    }
    
    public int getScreenY() {
        return JSUtil.getInt(getObject(), M_SCREEN_Y);
    }
    
    public int getInnerWidth() {
        return JSUtil.getInt(getObject(), M_INNER_WIDTH);
    }
    
    public int getInnerHeight() {
        return JSUtil.getInt(getObject(), M_INNER_HEIGHT);
    }
    
    public int getOuterWidth() {
        return JSUtil.getInt(getObject(), M_OUTER_WIDTH);
    }
    
    public int getOuterHeight() {
        return JSUtil.getInt(getObject(), M_OUTER_HEIGHT);
    }
    
    public int getLength() {
        return JSUtil.getInt(getObject(), M_LENGTH);
    }    
    
    /**
     * Start an applet dialog.
     * 
     * @param appletId the id of the applet
     */
    public void runDialog(String appletId) {
        getObject().call(F_RUN_DIALOG, new Object[]{appletId});
    }   
    
    /**
     * Start an applet element dialog.
     * 
     * This will include the element and the event object in addition to the script method name,
     * that creates the applet parameters.
     * 
     * @param element the element, that triggered the action
     * @param event the event, that triggered the action
     * @param appletId the id of the applet
     */
    public void runElementDialog(String appletId, JSNode element, JSEvent event) {
        getObject().call(F_RUN_ELEMENT_DIALOG, new Object[]{element.getObject(), event.getObject(), appletId});
    }   
    
    /**
     * Start a JSF action
     * 
     * @param form the JSF form
     * @param jsfId the JSF id
     */
    public void runJSFAction(String form, String jsfId, String windowId) {
        getObject().call(F_RUN_JSF_ACTION, new Object[]{form, jsfId, windowId});        
    }
    
}
